package com.zyl.blog.rbac.web.controller;

import com.zyl.blog.common.config.anno.SysLog;
import com.zyl.blog.common.domain.rbac.dto.LoginDTO;
import com.zyl.blog.common.domain.rbac.dto.RegisterDTO;
import com.zyl.blog.common.enums.BusinessType;
import com.zyl.blog.common.enums.OperationType;
import com.zyl.blog.common.response.Result;
import com.zyl.blog.rbac.service.rbac.UserService;
import io.swagger.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @version v1.0
 * @ProjectName: Personal_Blog
 * @Package: com.zyl.web.controller
 * @ClassName: AuthController
 * @Description:
 * @Author FinalFantasy
 * @Date 2025/6/23-15:51
 */

@RequiredArgsConstructor
@RestController
@RequestMapping("/rbac/")
@Validated
public class AuthController {

    private final UserService userService;

    /**
     * 登录博客
     *
     * @param loginDTO 登录信息载荷
     * @return {@link Result }<{@link ? }>
     */
    @Operation(summary = "登录博客")
    @SysLog(
            value = "用户登录业务",
            recordResult = true,
            businessType = BusinessType.AUTH,
            operationType = OperationType.LOGIN
    )
    @PostMapping("login")
    public Result<?> doLogin(
            @RequestBody @Validated LoginDTO loginDTO
    ) {
        return Result.ok(userService.doLogin(loginDTO));
    }


    /**
     * 注册博客
     *
     * @param registerDTO 注册信息载荷
     * @return {@link Result }<{@link ? }>
     */
    @Operation(summary = "注册博客")
    @SysLog(
            value = "用户注册业务",
            recordResult = true,
            businessType = BusinessType.AUTH,
            operationType = OperationType.REGISTER
    )
    @PostMapping("register")
    public Result<?> doRegister(
            @RequestBody @Validated RegisterDTO registerDTO
    ) {
        return userService.doRegister(registerDTO);
    }

}
